﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;

namespace WaterService.Menus
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Menu”。
    public class Menu : IMenu
    {
        public int SID { get; set; }
        public string URL { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string NodeID { get; set; }
        public string PNodeID { get; set; }
        public string ImageUrl { get; set; }

        public IList<Menu> GetMenus(string umenu)
        {            
            sqldb db = new sqldb();
            string sql = "select * from Tbt_SitMap b "
                        + "where Exists(select * from Tbt_UserAndMenu a where a.UserName = '" 
                        + umenu + "' and a.SID = b.NodeID)";
            DataSet ds = db.ExecuteDataset(sqlconn.GetConnStr(), CommandType.Text, sql);
            IList<Menu> menulist = null;
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                menulist = new List<Menu>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Menu objmenu = new Menu();
                    objmenu.SID = Convert.ToInt32(dr["SID"]);
                    objmenu.URL = dr["URL"].ToString();
                    objmenu.Title = dr["Title"].ToString();
                    objmenu.Description = dr["Description"].ToString();
                    objmenu.NodeID = dr["NodeID"].ToString();
                    objmenu.PNodeID = dr["PNodeID"].ToString();
                    objmenu.ImageUrl = dr["ImageUrl"].ToString();
                    menulist.Add(objmenu);
                }
            }
            return menulist;            
        }
    }
}
